# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/13 19:09
# @Author   : Robot-Zsj
"""
description:

i:
0 9 20 -1 -1 15 7 -1 -1 -1 -1 3 2

o:
38

"""

times = list(map(int, input().split()))


def getResult():
    ans = 0

    queue = [0]

    while len(queue) > 0:
        fa = queue.pop(0)

        ch1 = 2 * fa + 1
        ch2 = 2 * fa + 2

        ch1_exist = ch1 < len(times) and times[ch1] != -1
        ch2_exist = ch2 < len(times) and times[ch2] != -1

        if ch1_exist:
            times[ch1] += times[fa]
            queue.append(ch1)

        if ch2_exist:
            times[ch2] += times[fa]
            queue.append(ch2)

        if not ch1_exist and not ch2_exist:
            ans = max(ans, times[fa])

    return ans


print(getResult())
